/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JDialogGara.java
 *
 * Created on 29-mar-2012, 17.53.53
 */
package it.nesimuge.score.gui;

import it.lapomuge.db.dao.DbManagerGare;
import it.lapomuge.db.entity.Gara;
import it.nesimuge.score.gui.listener.LinstenerGareChanged;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Muge
 */
public class JDialogGara extends javax.swing.JDialog {

    List<LinstenerGareChanged> linst = new ArrayList<LinstenerGareChanged>();
    /** Creates new form JDialogGara */
    public JDialogGara(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    
    public void add(LinstenerGareChanged l){
        this.linst.add(l);
    }
    
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jNomeGara = new javax.swing.JTextField();
        jSalvaButton = new javax.swing.JButton();
        jAnnulla = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        
        jLabel1.setText(""); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jNomeGara.setName("jNomeGara"); // NOI18N

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("it/nesimuge/score/gui/resources/ScoreView"); // NOI18N
        jSalvaButton.setText(bundle.getString("gara.salva")); // NOI18N
        jSalvaButton.setName("jSalvaButton"); // NOI18N
        jSalvaButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jSalvaButtonMouseClicked(evt);
            }
        });

        jAnnulla.setText(bundle.getString("gara.annulla")); // NOI18N
        jAnnulla.setName("jAnnulla"); // NOI18N
        jAnnulla.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jAnnullaMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jNomeGara, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jAnnulla)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 254, Short.MAX_VALUE)
                        .addComponent(jSalvaButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jNomeGara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jSalvaButton)
                    .addComponent(jAnnulla))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jAnnullaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jAnnullaMouseClicked
this.setVisible(false);
}//GEN-LAST:event_jAnnullaMouseClicked

private void jSalvaButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSalvaButtonMouseClicked
    
	Gara g = new Gara();
    g.setNome(this.jNomeGara.getText());
    
    DbManagerGare.getInstance().save(Gara.class, g);
    for (LinstenerGareChanged l : linst) {
        l.fireGareChanged(this);
    }
    
}//GEN-LAST:event_jSalvaButtonMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JDialogGara.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JDialogGara.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JDialogGara.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JDialogGara.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                JDialogGara dialog = new JDialogGara(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAnnulla;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jNomeGara;
    private javax.swing.JButton jSalvaButton;
    // End of variables declaration//GEN-END:variables
}
